<template>
  <div>
    <el-form ref="form" :model="form" :rules="rules" :disabled="pageDisabled" label-width="80px">
     

      <el-form-item label="编号" prop="code">
        <el-input v-model="form.code" placeholder="请输入编号" />
      </el-form-item>
      <el-form-item label="名称" prop="name">
        <el-input v-model="form.name" placeholder="请输入名称" />
      </el-form-item>
      <el-form-item label="类别" prop="type">
        <el-select v-model="form.type" placeholder="请选择类别">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item label="发生部门" prop="deptIds">
             <!-- :show-all-levels="false"  显示全路径    separator="-"  分隔符  -->
             <!-- [props]
                multiple : true,  多选
                checkStrictly:true,   选择任意级别
                emitPath :false , 不是数组

         -->
             <el-cascader v-model="form.deptIds"
               :options="deptOptions"
               :props="{ expandTrigger: 'hover' ,  value: 'id'   ,emitPath:false , multiple : true,   }"

               clearable filterable placeholder="请选择部门">
               <template slot-scope="{ node, data }">
                 <span>{{ data.label }}</span>
                 <span v-if="!node.isLeaf"> ({{ data.children.length }}) </span>
               </template>
             </el-cascader>
           </el-form-item>

      <el-form-item label="状态">
        <el-radio-group v-model="form.status">
          <el-radio label="1">请选择字典生成</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="部门ID" prop="deptId">
        <el-input v-model="form.deptId" placeholder="请输入部门ID" />
      </el-form-item>
      <el-form-item label="发生时间" prop="findTime">
        <el-date-picker clearable size="small" style="width: 200px" v-model="form.findTime" type="date" value-format="yyyy-MM-dd"
          placeholder="选择发生时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="金额" prop="totalAmount">
        <el-input v-model="form.totalAmount" placeholder="请输入金额" />
      </el-form-item>
      <el-form-item label="删除标志" prop="delFlag">
        <el-input v-model="form.delFlag" placeholder="请输入删除标志" />
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
      </el-form-item>
    </el-form>

    


    <!--{{dataItems}} <el-button type="primary" @click="addDataItems">添加</el-button>-->
 <div slot="footer" v-if="!pageDisabled" class="dialog-footer">
    
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>


  </div>

</template>

<script>
  import {
    getInfo,
    addInfo,
    updateInfo
  } from "@/api/kri/Info";
   import { treeselect  } from "@/api/system/dept";
  import Editor from '@/components/Editor';
  export default {
    name: "InfoDetailBase",
    components: {
      Editor
    },
    props: {
      detailDialog: {
        type: Object,
        default: function() {
          return {
            // id
            id: null,
            open: null,
            // 是否详情页
            isDisabled: null,
          }
        },
      },
    },

    data() {
      return {
        // 表单参数
        form: {},
        dataItems: ['a', 'b', 'c'],
        deptOptions: undefined,

        // 表单校验
        rules: {}
      };
    },
    created() {
      this.initDate();
      this.initDicts();
    },

    computed: {
      pageDisabled: function() {
        return this.detailDialog.isDisabled;
      },
    },

    watch: {
      /* 监听打开状态 */
      "detailDialog.open": function(newOpen, oldOpen) {
        //显示则刷新
        if (newOpen) {
          console.log(this.$options.name + "监听打开状态", this.detailDialog.id)
          this.initDate();
        }
      },
    },
    methods: {


      /* 初始化form */
      initDate() {

        if (this.detailDialog.id) {
          getInfo(this.detailDialog.id).then(response => {
            this.form = response.data;
          });
        } else {
          //新增页面清空
          this.form = {};
        }
      },

      /* 加载码表 */
      initDicts() {
         this.getTreeselect();
      },

      /** 查询部门下拉树结构 */
      getTreeselect() {
        treeselect().then(response => {
          this.deptOptions = response.data;
        });
      },
    // addDataItems(){
    //   this.$set( this.dataItems, 1, 'xxx')
    //     // this.dataItems[1]='xxx'
    //     // this.dataItems.length = 2 
    //     console.log(this.dataItems)
    // },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              updateInfo(this.form).then(response => {
                this.msgSuccess("修改成功");
                this.parentRefresh();
              });
            } else {
              addInfo(this.form).then(response => {
                this.msgSuccess("新增成功");
                this.parentRefresh();
              });
            }
          }
        });
      },
      /* 关闭子页面*/
      cancel() {

        this.detailDialog.open = !this.detailDialog.open
        this.$emit("update:detailDialog", this.detailDialog);
      },

      /* 关闭子页面刷新父页面 */
      parentRefresh() {
        this.cancel();
        this.$emit("doRefresh");
      },



    },

  }
</script>

<style>
</style>
